#include ("/_includes/_layout.html")
#@layout("邀请码管理", "wxmall,点步科技", "Wxmall社区","wxmall") 
#define content()
<div class="wrapper wrapper-content">
		<div class=" content-tabs">
			<nav class="page-tabs J_menuTabs">
		       <div class="page-tabs-content">
		       	   <a href="#(webctx)/invitecode/rule" class="J_menuTab">邀请码规则</a>
		           <a href="#(webctx)/invitecode" class="J_menuTab">邀请码统计</a>
		           <a href="#(webctx)/invitecode/cash" class="J_menuTab active">提现管理</a>
		       </div>
		   	</nav>
		</div>
		<div class="content  ibox-content">
			<table class="table table-striped table-bordered bootstrap-datatable datatable">
				<tr>
					<td colspan="3" style="text-align: left;">&nbsp;&nbsp;
					<input type="text" name="q_pond_txt" id="q_pond_txt" class="control-inline"  style="width:190px;" placeholder="输入手机号"/>
					&nbsp;&nbsp;&nbsp;
					<select id="a_status_sel" class="control-inline" style="width: 102px">
						<option value="">全部</option>
						<option value="1" selected="selected">等待打款</option>
						<option value="2">已打款</option>
						<option value="3">取消打款</option>
					</select>
					&nbsp;&nbsp;&nbsp;
					<button id="myqueryBtn" class="btn btn-success btn-sm">查询</button>
					</td>
				</tr>
			</table>
			<div class="panel-body">
				<div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>	
			</div>
			<table id="mainTable" class="table table-striped table-bordered bootstrap-datatable datatable" border="0">
			  <thead>
				  <tr>
					<th><input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/></th>
					<th>手机号</th>
					<th>提现金额</th>
					<th>账户类型</th>
					<th>提现账户</th>
					<th>申请时间</th>
					<th>备注</th>
					<th>状态</th>
					<th>操作</th>
				  </tr>
			  </thead>   
			  <tbody class="itemsLotGrid"></tbody>
		  	</table>
		</div>
</div>
<script type="text/html" id="item_table_tr_tpl">
{{each list as item i}}
		<tr class="package">
			<td><input type="checkbox" class="commchk" id="checkbox_{{item.scr_id}}" style="margin-right: 4px; vertical-align: middle;"/></td>
			<td>{{item.phone}}</td>
			<td>{{item.want_cash}}</td>
			<td>{{if item.cash_type == 1}} 支付宝 {{else}} 银行卡 {{/if}}</span></td>
			<td>{{item.cash_account}}</td>
			<td>{{item.created}}</td>
			<td>{{item.memo}}</td>
			<td>{{if item.status == 1}}待打款{{else if item.status==2}}已打款<br>打款时间:<br>{{item.updated}} {{else}} 取消打款 {{/if}}</td>
			<td>
				&nbsp;<a id="confirm_{{item.scr_id}}" {{if item.status != 1}}style="display:none;"{{/if}} href="javascript:void(0)">确认打款</a>
				&nbsp;<a id="cancel_{{item.scr_id}}" {{if item.status != 1}}style="display:none;"{{/if}} href="javascript:void(0)">取消打款</a>
			</td>
		</tr>
{{/each}}
</script>
<script type="text/template" id="table_noresult_tr_tpl">
	<tr class="package"><td colspan="9" class="center">没有结果集</td></tr>
</script>
#end
<script type="text/javascript">
$(document).ready(function() {
	var params = {};
	params.status = $("#a_status_sel").val();
	var table = new obz.TableView("pager", obz.ctx + "/invitecode/cashlist", params, function(resp){
		$(".itemsLotGrid").empty();
		if(resp && resp.list && resp.list.length>0){
			$('.itemsLotGrid').html(template('item_table_tr_tpl', resp));
			//初始化checkbox点击事件
			TBatch.checkCheckbox();
			TBatch.initCheckboxClick();
			TBatch.initOptEvent(TableOpt.init());
		}else{
			$(".itemsLotGrid").append($("#table_noresult_tr_tpl").html());
		}
	});
	table.init();
	
	var TableOpt = {
		confirmCash : function(param){
			obz.showMessage("通过手动转账成功后，再确认打款！", function(){
	   			var id = param[1];
	    		obz.ajaxJson(obz.ctx + "/invitecode/confirmCash", {id: id}, function(resp){
	    			if(resp.code==200){
	    				obz.msg("已确认打款", function(){table.init();});
	    			}
	    		});
	   		});
			return false;
		},	
		cancelCash : function(param){
			parent.layer.prompt({
    		    title: '请输入不打款原因',
    		    formType: 2 //prompt风格，支持0-2
    		}, function(pass){
    		    obz.ajaxJson(obz.ctx + "/invitecode/cancelCash", {id: param[1], content: pass}, function(resp){
    		    	if(resp.code == 200){
    		    		layer.msg("取消打款成功", function(){
		    				table.init();
	        		    });
	    			}else{
	    				layer.msg(resp.msg == null ? "系统错误" : resp.msg);
	    			}
	    		});
    		});
			return false;
		},	
		init : function(){
			var optArray = new Array();
			optArray.push(this.confirmCash);
			optArray.push(this.cancelCash);
			return optArray;
		}
	}
	
	$("#myqueryBtn").click(function(){
		params.phone = $("#q_pond_txt").val();
		params.status = $("#a_status_sel").val();
		table.init();
	});
});
</script>
<script>
Template.init("#menu-invitecode");
</script>